import React from 'react'


class App extends React.PureComponent{
  constructor(props) {
    super(props)
  
    this.state = {
       obj : {number: 0}
    }
  }
  
  // 前置知识 对象内容、对象引用
  // 考察学生 
  // let obj = {number: 1}
  // let obj2 = obj
  // obj.number = 2
  // obj === obj2 ?
  // let obj3 = {number: 2}
  // obj === obj3 ?
  // 第二个知识点：对象展开操作运算符


  handleCount = () => {
    this.setState((state, props) => {
      state.obj.number = 3
      return {
        obj: state.obj
        // obj: {...state.obj, number: 3} // 正确做法
      }
    }, () => {console.log('最新的', this.state.obj.number)})
  }

  render () {
    console.log('render=========', this.state.obj.number)
    return (
      <div>
        <h2>{this.state.obj.number}</h2>
        <button onClick={this.handleCount}>生成随机数</button>
      </div>
    )
  }

}

export default App